package com.mapper;

import com.javabean.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author: 张波
 * @Time: 2025/8/28 14:43
 */
public interface PermissionMapper {
	/// 查询所有权限
	@Select("select * from project.permission")
	List<Permission> selectAll();
	/// 添加权限
	@Insert("insert into project.permission ( permissionName,url) values (#{arg0}, #{arg1})")
	void insertPermission(String permissionName,String url);

	/// 根据id进行查询
	@Select("select * from project.permission where id = #{id}")
	Permission selectById(int id);

	/// 修改权限 根据id进行修改
	@Update("update project.permission set permissionName=#{permissionName},url=#{url}  where id = #{id}")
	void updateOneById(Permission permission);

	/// 删除权限根据id进行删除
	@Delete("delete from project.permission where id =#{id}")
	int deleteById(int id);

	/// 关联Permission表和Role表查询
	@Select("select * from permission p inner join role_permission rp  on p.id = rp.permissionId where rp.roleId = #{rid}")
	List<Permission> selectByRid(int rid);
}
